<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="author" content="wangbo">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    // 限定符 数字出现0次或者1次{0,1}
    let reg = /^张\d?$/
    // 可以0 ,无穷 {0,}
    let reg2 = /^张\d*$/
    // 1,无穷 {1,}
    let reg3 = /^张\d+$/
    // | 或者
    let reg4 = /^张三|四$/
    console.log("现0次或者1", reg.test("张"), reg.test("张1"))
    console.log("0 ,无穷", reg2.test("张"), reg2.test("张11111"))
    console.log("1 ,无穷", reg3.test("张"), reg3.test("张11111"))
    console.log("| 或者", reg4.test("张四"), reg4.test("张25"))
    // 手机号
    let phone_reg = /^1\d{10}$/
    console.log("手机号", phone_reg.test("13011111111"), reg4.test("130"))
    // qq邮箱
    let qq_reg = /^[a-zA-Z\d]+@qq.com$/
    console.log("qq邮箱", qq_reg.test("130@qq.com"), qq_reg.test("sdf@qq.com"), qq_reg.test("sdf@163.com"))


    let str = "my-hello-word"
    // my hello word
    str = str.replace(/-/g, " ");
    // \b 匹配单词  like word
    // \d 数字 0-9 
    str = str.replace(/\b\w/g, function (str) {
      return str.toUpperCase();
    })
    //  
    str = str.replaceAll(" ", '');
    console.log(str);
  </script>
</body>

</html>